//
//  XLChannelControl.m
//  XLChannelControlDemo
//
//  Created by MengXianLiang on 2017/3/3.
//  Copyright © 2017年 MengXianLiang. All rights reserved.
//

#import "XLChannelControl.h"
#import "XLChannelView.h"

@interface XLChannelControl (){
//    UINavigationController *_nav;
    
    XLChannelView *_channelView;
    
    ChannelBlock _block;
}
@end

@implementation XLChannelControl

+(XLChannelControl*)shareControl{
    static XLChannelControl *control = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        control = [[XLChannelControl alloc] init];
    });
    return control;
}

-(instancetype)init
{
    if (self = [super init]) {
        _channelView = [[XLChannelView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    return self;
}



-(void)backMethod{
    _block(_channelView.inUseTitles,_channelView.unUseTitles);
}

-(void)showChannelViewWithInUseTitles:(NSArray*)inUseTitles unUseTitles:(NSArray*)unUseTitles finish:(ChannelBlock)block{
    _block = block;
    _channelView.inUseTitles = [NSMutableArray arrayWithArray:inUseTitles];
    _channelView.unUseTitles = [NSMutableArray arrayWithArray:unUseTitles];
    [_channelView reloadData];

//    CGRect frame = _nav.view.frame;
//    frame.origin.y = - _nav.view.bounds.size.height;
//    _nav.view.frame = frame;
//    _nav.view.alpha = 0;
//    [[UIApplication sharedApplication].keyWindow addSubview:_nav.view];
//    [UIView animateWithDuration:0.3 animations:^{
//        _nav.view.alpha = 1;
//        _nav.view.frame = [UIScreen mainScreen].bounds;
//    }];
}

-(void)addChannelToView:(UIView *)view
                  point:(CGPoint)point
            inUseTitles:(NSArray*)inUseTitles
            unUseTitles:(NSArray*)unUseTitles
                 finish:(ChannelBlock)block{
    
    _block = block;
    _channelView.inUseTitles = [NSMutableArray arrayWithArray:inUseTitles];
    _channelView.unUseTitles = [NSMutableArray arrayWithArray:unUseTitles];
    [_channelView reloadData];
    _channelView.frame = CGRectMake(point.x, point.y, [UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);
    [view addSubview:_channelView];

}

@end
